#!/bin/bash
source /etc/profile
basedir=`dirname $0`
cd $basedir
for i in `ls -t *.jar`
do
    #echo $i
    break
done

ii=${i%.*}
#echo $ii
TaskID=$(ps -ef |grep -w $ii|grep -v 'grep'|awk '{print $2}')
input=$1
start()
{
  if [ ${TaskID} ];then
     echo "此服务已启动!"
  else
     nohup java -Xbootclasspath/a:./config -Djava.ext.dirs=./lib:${JAVA_HOME}/jre/lib/ext -jar $(pwd)/$i spring > nohup.out 2>&1 &
     #nohup java -Xbootclasspath/a:./config -Djava.ext.dirs=./lib:${JAVA_HOME}/jre/lib/ext -jar $(pwd)/$i spring > /dev/null &2>&1 &
     # tail -f  nohup.out
  fi
}

stop()
{
  if [ ${TaskID} ];then
     kill -9 ${TaskID}
     echo "服务已经停止启动"
  else
     echo "服务没有启动"
  fi
}

status()
{
  if [ ${TaskID} ];then
    echo "此服务已启动!"
  else
    echo "服务没有启动!"
  fi
}

if [ -z "$input" ]
then
  echo "用法： ./startup.sh {start|stop|status}"
elif [ ${input} == "start" ]
then
   start
elif [ ${input} == "stop" ]
then
   stop
elif [ ${input} == "status" ]
then
   status
else
  echo "用法： ./startup.sh {start|stop|status}"
fi
